<template>
   <div>
    <h3>会员等级增加页面</h3>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="right">等级名称</td>
          <td><input type="text" v-model="queryInfo.LevelName" /></td>
        </tr>
        <tr>
          <td align="right"></td>
          <td><input type="button" value="增加" @click="ok" /></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import{ref,reactive} from 'vue';
import axios from 'axios';
import { useRouter} from 'vue-router';
const router=useRouter();
let queryInfo=reactive({
    LevelName:'',
});
const ok = () => {
  //1.判断非空
  if (queryInfo.LevelName == '') {
    alert('等级名称不能为空');
    return;
  }
  //2.发送网络请求
  axios({
    url: '/api/Members/AddMemberLevel',
    method: 'post',
    data: queryInfo,
  })
    .then((res) => {
      //res就是后端返回的结果
      console.log(res);
      if (res.data == -1) {
        alert('等级名称重复');
        return;
      } else if (res.data == -2) {
        alert('添加等级失败');
        return;
      } else {
        alert('添加成功');
        //跳转
        router.push('/memberLevelList');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped>

</style>